//
//  MineAboutViewController.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/22.
//

import UIKit

class MineAboutViewController: BaseViewController {
    var dataSourceArr: [MineModel] = [MineModel]()
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNavi()
        setupUI()
        loadTestData()
    }
    private func setupNavi() {
        navigationItem.title = "关于"
    }
    private func setupUI() {
        view.addSubviews(appIconImageView, versionLabel, tableView)
        appIconImageView.snp.makeConstraints { make in
            make.top.equalTo(100)
            make.centerX.equalToSuperview()
            make.width.equalTo(121)
            make.height.equalTo(121)
        }
        versionLabel.snp.makeConstraints { make in
            make.top.equalTo(appIconImageView.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
        }
        tableView.snp.makeConstraints { make in
            make.top.equalTo(versionLabel.snp.bottom).offset(100)
            make.left.right.bottom.equalToSuperview()
        }
    }
    private func loadTestData() {
        dataSourceArr.append(MineModel(iconStr: "", titleStr: "帮助导航", type: 1))
        dataSourceArr.append(MineModel(iconStr: "", titleStr: "隐私协议", type: 2))
        dataSourceArr.append(MineModel(iconStr: "", titleStr: "版本更新", type: 3))
        dataSourceArr.append(MineModel(iconStr: "", titleStr: "官方网站", type: 4))
        dataSourceArr.append(MineModel(iconStr: "", titleStr: "支持设备", subTitle: "Android、IOS", type: 5))
        tableView.reloadData()
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var appIconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "xingtu_logo_icon")
        return imageView
    }()
    private lazy var versionLabel: UILabel = {
        let label = UILabel()
        if let infoDictionary = Bundle.main.infoDictionary, let version = infoDictionary["CFBundleShortVersionString"] as? String {
            print("App 版本号为：\(version)")
            label.text = "星图\(version)"
        }
        label.textColor = .lxs.hex("#FFFFFF")
        label.font = .lxs.font(size: 16)
        label.textAlignment = .center
        return label
    }()
    private lazy var tableView: UITableView = {
        let tableView = UITableView(frame: .zero, style: .grouped)
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.registerCellClass(MineAboutTableViewCell.self)
        tableView.backgroundColor = .clear
        return tableView
    }()
}

extension MineAboutViewController: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        dataSourceArr.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(MineAboutTableViewCell.self, for: indexPath)
        cell.model = dataSourceArr[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        60
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
}
